home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / src / defun.h < prev    next >
C/C++ Source or Header  |  1996-10-26  |  6KB  |  165 lines

  1. /*
  2.  
  3. Copyright (C) 1996 John W. Eaton
  4.  
  5. This file is part of Octave.
  6.  
  7. Octave is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2, or (at your option) any
  10. later version.
  11.  
  12. Octave is distributed in the hope that it will be useful, but WITHOUT
  13. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15. for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with Octave; see the file COPYING.  If not, write to the Free
  19. Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. */
  22.  
  23. #if !defined (octave_defun_h)
  24. #define octave_defun_h 1
  25.  
  26. #if defined (octave_defun_dld_h)
  27. #error defun.h and defun-dld.h both included in same file!
  28. #endif
  29.  
  30. #include "defun-int.h"
  31.  
  32. // Define a builtin variable.
  33. //
  34. //   name is the name of the variable, unquoted.
  35. //
  36. //   defn is the initial value for the variable.
  37. //
  38. //   ins_as_fcn is a flag that says whether to install the variable as
  39. //     if it were a function (allowing the name to also be used as a
  40. //     variable by users, but recover its original definition if cleared).
  41. //
  42. //   protect is a flag that says whether it should be possible to give
  43. //     the variable a new value.
  44. //
  45. //   eternal is a flag that says whether it should be possible to
  46. //     clear the variable.  Most builtin variables are eternal, and
  47. //     cannot be cleared.
  48. //
  49. //   sv_fcn is a pointer to a function that should be called whenever
  50. //     this variable is given a new value.  It can be 0 if there is no
  51. //     function to call.  See also the code in user-prefs.cc.
  52. //
  53. //   doc is the simple help text for this variable.
  54.  
  55. #define DEFVAR(name, defn, inst_as_fcn, sv_fcn, doc) \
  56.   DEFVAR_INT (#name, SBV_ ## name, defn, inst_as_fcn, 0, sv_fcn, doc)
  57.  
  58. // Define a builtin-constant, and a corresponding variable that can be
  59. // redefined.  This is just the same as DEFVAR, except that it defines
  60. // `name' as a variable, and `__name__' as a constant that cannot be
  61. // redefined.
  62.  
  63. #define DEFCONST(name, defn, inst_as_fcn, sv_fcn, doc) \
  64.   DEFVAR_INT (#name, SBV_ ## name, defn, inst_as_fcn, 0, sv_fcn, doc); \
  65.   DEFVAR_INT ("__" ## #name ## "__", XSBV_ ## name, defn, 0, 1, sv_fcn, doc)
  66.  
  67. // This one can be used when `name' cannot be used directly (if it is
  68. // already defined as a macro).  In that case, name is already a
  69. // quoted string, and the name of the structure has to be passed too.
  70.  
  71. #define DEFCONSTX(name, sname, defn, inst_as_fcn, sv_fcn, doc) \
  72.   DEFVAR_INT (name, sname, defn, inst_as_fcn, 0, sv_fcn, doc); \
  73.   DEFVAR_INT ("__" ## name ## "__", X ## sname, defn, 0, 1, sv_fcn, doc)
  74.  
  75. // How builtin variables are actually installed.
  76.  
  77. #define DEFVAR_INT(name, sname, defn, inst_as_fcn, protect, sv_fcn, doc) \
  78.   do \
  79.     { \
  80.       builtin_variable sname (name, octave_value (defn), inst_as_fcn, \
  81.                   protect, (sv_fcn != 0), sv_fcn, doc); \
  82.       install_builtin_variable (sname); \
  83.     } \
  84.   while (0)
  85.  
  86. // Define a builtin function.
  87. //
  88. //   name is the name of the function, unqouted.
  89. //
  90. //   args_name is the name of the octave_value_list variable used to pass
  91. //     the argument list to this function.
  92. //
  93. //   nargout_name is the name of the int variable used to pass the
  94. //     number of output arguments this function is expected to produce.
  95. //
  96. //   doc is the simple help text for the function.
  97.  
  98. #define DEFUN(name, args_name, nargout_name, doc) \
  99.   DEFUN_INTERNAL (name, args_name, nargout_name, 0, doc)
  100.  
  101. // Define a builtin text-style function.
  102. //
  103. // This is like DEFUN, except that it defines a function that can be
  104. // called from the Octave language without using parenthesis to
  105. // surround the arguments). 
  106.  
  107. #define DEFUN_TEXT(name, args_name, nargout_name, doc) \
  108.   DEFUN_INTERNAL (name, args_name, nargout_name, 1, doc)
  109.  
  110. // Define a mapper function.
  111. //
  112. //   name is the name of the function, unquoqted.
  113. //
  114. //   ch_map is a pointer to a function that should be called for
  115. //     integer arguments that are expected to creat integer results.
  116. //     (It's a kluge to handle character mappers like isalpha.)
  117. //
  118. //   d_d_map is a pointer to a function that should be called for real
  119. //     arguments that are expected to create real results.
  120. //
  121. //   d_c_map is a pointer to a function that should be called for real
  122. //     arguments that are expected to create complex results.
  123. //
  124. //   c_c_map is a pointer to a function that should be called for
  125. //     complex arguments that are expected to create complex results.
  126. //
  127. //   lo is the lower bound of the range for which real arguments can
  128. //     become complex.  (e.g., lo == -Inf for sqrt).
  129. //
  130. //   hi is the upper bound of the range for which real arguments can
  131. //     become complex.  (e.g., hi == 0 for sqrt).
  132. //
  133. //   can_ret_cmplx_for_real is a flag that says whether this function
  134. //     can create a complex number given a real-valued  argument
  135. //     (e.g., sqrt (-1)).
  136. //
  137. //   doc is the simple help text for the function.
  138.  
  139. #define DEFUN_MAPPER(name, ch_map, d_d_map, d_c_map, c_c_map, \
  140.              lo, hi, can_ret_cmplx_for_real, doc) \
  141.   do \
  142.     { \
  143.       builtin_mapper_function S ## name (ch_map, d_d_map, \
  144.                      d_c_map, c_c_map, lo, hi, \
  145.                      can_ret_cmplx_for_real, \
  146.                      #name, doc); \
  147.       install_builtin_mapper (S ## name); \
  148.     } \
  149.   while (0)
  150.  
  151. // Make alias another name for the existing function name.  This macro
  152. // must be used in the same file where name is defined, after the
  153. // definition for name.
  154.  
  155. #define DEFALIAS(name, alias) \
  156.   DEFALIAS_INTERNAL (name, alias)
  157.  
  158. #endif
  159.  
  160. /*
  161. ;;; Local Variables: ***
  162. ;;; mode: C++ ***
  163. ;;; End: ***
  164. */
  165.